import { Component, OnInit } from '@angular/core';
import {FormControl} from "@angular/forms";
import {MaintenanceService} from "../../shared/service/maintenance.service";

@Component({
  selector: 'app-maintenance-search',
  templateUrl: './maintenance-search.component.html',
  styleUrls: ['./maintenance-search.component.css']
})
export class MaintenanceSearchComponent implements OnInit {
  public searchParam: FormControl = new FormControl();
  constructor(private maintenanceService:MaintenanceService) {
    this.searchParam.valueChanges
      .debounceTime(500)
      .subscribe(
        value => {
          this.maintenanceService.searchEvent.emit(value);
        }
      );

    this.maintenanceService.searchFreshEvent.subscribe(
      param => {
        if (param) {
          this.searchParam.patchValue("");
        }
      }
    );
  }

  ngOnInit() {
  }

}
